/*
 * @Author: 噜噜雯雯 2199987619@qq.com
 * @Date: 2025-06-05 09:40:30
 * @LastEditors: 噜噜雯雯 2199987619@qq.com
 * @LastEditTime: 2025-07-18 15:59:06
 * @FilePath: \linePatrol\vue-element-plus-admin\src\store\modules\dictData.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { defineStore } from 'pinia'
import { store } from '../index'
import GetSystemDictApi from '@/api/dictionary/index'

export const useDictStore = defineStore('dict', {
  state: (): any => {
    return {
      //   Dict:[]
    }
  },
  getters: {
    getDict(dict): any {
      GetSystemDictApi.dictData({ dictType: dict }).then((res) => {
        return res
      })
    }
  },
  actions: {
    setDict(dict: string): any {
      this.$patch((state) => {
        if (state[`${dict}`]) {
          return state[`${dict}`]
        } else {
          GetSystemDictApi.dictData({ dictType: dict }).then((res) => {
            state[`${dict}`] = res.rows
            return res
          })
        }
      })
    },
    editDict(dict: string) {
      this.$patch((state) => {
        if (state[`${dict}`]) {
          //store中存在此字典，需修改
          //  return state[`${dict}`]
        }
      })
    }
  },
  persist: true
})

export const useUserStoreWithOut = () => {
  return useDictStore(store)
}
